package com.bed.lovewithpatientbed.service.impl;

import com.bed.lovewithpatientbed.dao.RoleDao;
import com.bed.lovewithpatientbed.pojo.Role;
import com.bed.lovewithpatientbed.pojo.RoleExample;
import com.bed.lovewithpatientbed.service.RoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Tyl
 * @version 1.0.0
 * @ClassName RoleServiceI.java
 * @Description TODO
 * @createTime 2020年10月20日 21:02:00
 */
@Service
@Transactional
public class RoleServiceI implements RoleService{
        @Resource
        RoleDao roleDao;
        @Override
        public void insertRole(Role role) {
            if(role!=null){
                roleDao.insert(role);
            }
        }
        @Override
        public void deleteRole(Integer roleId) {
            RoleExample example = new RoleExample();
            RoleExample.Criteria criteria = example.createCriteria();
            criteria.andRoleIdEqualTo(roleId);
            roleDao.deleteByPrimaryKey(roleId);
        }
            @Override
            public Role selectOne(Integer roleId) {
                Role role = roleDao.selectByPrimaryKey(roleId);
                return role;
            }
            public List<Role> selectAll() {
                    List<Role> roleList = roleDao.selectByExample(null);
                    return roleList;
                }

    @Override
    public void updateRole(Role role) {
        roleDao.updateByPrimaryKey(role);
    }

}
